<?php
namespace app\modules\test\models;

use app\libs\Method;
use app\libs\Pager;
use yii\db\ActiveRecord;

class TestList extends ActiveRecord
{

    public static function tableName()
    {
        return '{{%test_list}}';
    }

    public function getData($where, $pageSize = 10, $page = 1)
    {
        $limit = " limit " . ($page - 1) * $pageSize . ",$pageSize";
        $sql = "select tl.*,tc.name AS cateName from {{%test_list}} tl left join {{%test_cate}} tc on tl.subjectId=tc.id where $where order by id desc";
        $count = count(\Yii::$app->db->createCommand($sql)->queryAll());
        $data = \Yii::$app->db->createCommand($sql . $limit)->queryAll();
        $pageStr = Method::getPagedRows(['count' => $count, 'pageSize' => $pageSize, 'rows' => 'models']);
        return ['data' => $data, 'pageStr' => $pageStr];
    }

}
